<template>
  <div class="home">
    <div class="box">
      <div class="img">
        <img src="../assets/logo.png" alt="" />
      </div>
      <el-form ref="form" class="form" :model="form" :rules="rules">
        <el-form-item prop="username">
          <el-input
            v-model="form.username"
            type="text"
            placeholder="请输入用户名"
          ></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input
            v-model="form.password"
            type="password"
            placeholder="请输入密码"
          ></el-input>
        </el-form-item>
        <el-form-item class="but">
          <el-button type="primary" @click="path">登录</el-button>
          <el-button type="info" @click="del">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
 
<script>
import { All } from "../utils/API";
export default {
  data() {
    return {
      form: {
        username: "",
        password: "",
      },
      rules: {
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" },
          {
            min: 5,
            max: 10,
            message: "长度在 5 到 10 个字符",
            trigger: "blur",
          },
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          {
            min: 5,
            max: 10,
            message: "长度在 5 到 10 个字符",
            trigger: "blur",
          },
        ],
      },
    };
  },
  mounted() {

  },
  methods: {
    async path() {
      let res = await All("/login", this.form, "POST");
      // this.$store.commit("getToken", res.data.data);
      sessionStorage.setItem('user',JSON.stringify(res.data.data))
      if (res) {
        this.$router.push({ path: "/home" });
      }
    },
    del() {
      this.$refs.form.resetFields();
    },
  },
};
</script>
 
<style lang = "scss" scoped>
.home {
  width: 100%;
  height: 100%;
  position: relative;
  background-color: #2b4b6b;
  .box {
    box-sizing: border-box;
    width: 25%;
    height: 350px;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    margin: auto;
    background-color: white;
    border-radius: 5px;
    box-shadow: 0px 0px 10px white;
    padding: 0 40px;
    .form {
      margin-top: 140px;
      .but {
        display: flex;
        justify-content: flex-end;
      }
    }
    .img {
      width: 100px;
      height: 100px;
      overflow: hidden;
      position: absolute;
      left: 50%;
      top: -15%;
      border-radius: 50%;
      background-color: #efefef;
      transform: translateX(-50%);
      border: 10px solid white;
      box-shadow: 0px 0px 10px silver;
      img {
        width: 100%;
        height: 100%;
      }
    }
  }
}
</style>